package com.rimi.project.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.rimi.project.dao.UserDao;
import com.rimi.project.dao.impl.UserDaoImpl;

/**
 * Servlet implementation class RegisterServlet
 */
@WebServlet("/user/register")
public class RegisterServlet extends HttpServlet {
      
	UserDao userDao = new UserDaoImpl();

	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		String userName = req.getParameter("registerusername");
		
		String password = req.getParameter("registerpassword");
		
		if ("".equals(userName) || "".equals(password)) {
			userName = null;
			password = null;
		}
		
		boolean isRegister = userDao.insertUser(userName, password);
		
		if (isRegister) {
			resp.getWriter().print(isRegister);
		} else {
			resp.getWriter().print(!isRegister);
		}
//		req.getRequestDispatcher("/login.jsp").forward(req, resp);
	}

}
